﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace LabMS.Web.DictionaryMaintenance
{
    public partial class AddDictionary : Base.BasePage
    {
        public string TableName = "";
        public string TableDes1 = "";
        public string TableDes2 = "";
        public string DClass = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            strPagePrivilege.Add("ZDWH");
            strPageUserType.Add("mana");
             //为了避免乱码，要在web.config中写入:<globalization requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN" fileEncoding="gb2312"/>
            if (Request.QueryString["TableName"] != null)
            {
                TableName =Server.UrlDecode(Request.QueryString["TableName"].ToString());
            }
            if (Request.QueryString["TableDes1"] != null)
            {
                TableDes1 =Server.UrlDecode(Request.QueryString["TableDes1"].ToString());
            }
            if (Request.QueryString["TableDes2"] != null)
            {
                TableDes2 =Server.UrlDecode(Request.QueryString["TableDes2"].ToString());
            }
            if (Request.QueryString["DClass"] != null)
            {
                DClass =Server.UrlDecode(Request.QueryString["DClass"].ToString());
            }
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region 验证
            if (string.IsNullOrEmpty(tbCode.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "此项不能为空！");
                tbCode.Focus();
            }
            else if (string.IsNullOrEmpty(tbName.Text.Trim()))
            {
                Common.JShelper.JSAlert(this.Page, "", "此项不能为空！");
                tbName.Focus();
            }
            #endregion
            else
            {
                ExtendBLL.Dictionary EB = new ExtendBLL.Dictionary();
                LabMS.Model.Dictionary MD = new LabMS.Model.Dictionary();
                if (EB.IsCodeExist(DClass, tbCode.Text.Trim()) == 0)
                {
                    Common.JShelper.JSAlert(this.Page, "", "该值已经存在！");
                    tbCode.Text = "";
                    tbCode.Focus();
                }
                else
                {
                    MD.DClass = DClass;
                    MD.Name = tbName.Text.Trim();
                    MD.Code = tbCode.Text.Trim();

                    int count = EB.Add(MD);
                    if (count > 0)
                    {
                        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('新增成功！');window.opener.location.href=window.opener.location.href;self.close();</script>");
                    }
                }
            }

        }
    }
}
